package likou.tanxin;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/06 19:19
 */
public class _861 {
    public static void main(String[] args) {
        System.out.println(matrixScore(new int[][]{{0, 0, 1, 1}, {1, 0, 1, 0}, {1, 1, 0, 0}}));
        System.out.println(matrixScore(new int[][]{{1, 1, 1, 1}, {1, 0, 0, 1}, {1, 1, 1, 1}}));
    }

    public static int matrixScore(int[][] A) {
        int daan = 0;
        for (int hang = 0; hang < A.length; hang++) {
            //有一列的第一个为0，则这行全换
            if (A[hang][0] == 0) {
                for (int i = 0; i < A[hang].length; i++) {
                    A[hang][i] = A[hang][i] ^ 1;
                }
            }
        }
        //第一行必须全为1
        daan += (A.length * Math.pow(2.0, A[0].length - 1));
        for (int lie = 1; lie < A[0].length; lie++) {
            int nowLieNum = 0;
            for (int h = 0; h < A.length; h++) {
                nowLieNum += A[h][lie];
            }
            //得到这一列的值
            nowLieNum = nowLieNum < A.length / 2 + A.length % 2 ? A.length - nowLieNum : nowLieNum;
            daan += (nowLieNum * Math.pow(2.0, A[0].length - lie - 1));
        }
        return daan;
    }

    public static int hangNum(int[] hang) {
        int num = 0;
        int now = 1;
        for (int i = hang.length - 1; i >= 0; i--) {
            num += now * hang[i];
            now *= 2;
        }
        return num;
    }
}
